package chapter10;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/4/13 13:37
 */
interface Services {
    void method1();

    void method2();
}

interface ServiceFacotry {
    Services getService();
}

class Implementation1 implements Services {
    public static ServiceFacotry facotry = () -> new Implementation1();

    private Implementation1() {

    }

    @Override
    public void method1() {
        System.out.println("Implementation1 method1");
    }

    @Override
    public void method2() {
        System.out.println("Implementation1 method2");
    }
}

class Implementation2 implements Services {
    public static ServiceFacotry facotry = () -> new Implementation2();

    private Implementation2() {

    }

    @Override
    public void method1() {
        System.out.println("Implementation2 method1");
    }

    @Override
    public void method2() {
        System.out.println("Implementation2 method2");
    }
}

public class Facotries {
    public static void serviceConsumer(ServiceFacotry facotry) {
        Services services = facotry.getService();
        services.method1();
        services.method2();
    }

    public static void main(String[] args) {
        serviceConsumer(Implementation1.facotry);
        serviceConsumer(Implementation2.facotry);
    }
}
